package com.qdu.mapper;

import com.qdu.bean.RentCarBean;
import com.qdu.bean.TimeBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MonthMapper extends Mapper<LongWritable, Text, TimeBean, RentCarBean> {

    private TimeBean keyOut = new TimeBean();
    private RentCarBean valueOut = new RentCarBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //切分列
        String[] items = value.toString().split(",");
        String[] fulltime = items[0].split(" ");
        String[] ymd = fulltime[0].split("/");
        //取出列
        String year = ymd[0];         //年
        String month = ymd[1];        //月
        int casual = Integer.parseInt(items[9]);     //未注册的人数
        int registered = Integer.parseInt(items[10]); //注册了的人数
        int count = Integer.parseInt(items[11]);      //注册+未注册

        //封装对象
        keyOut.set2(year+'-'+month);   //传 年+月
        valueOut.set1(casual,registered,count);

        //写出
        context.write(keyOut,valueOut);
    }
}